package com.tengju.support.domain.model.message;

import com.google.common.collect.Lists;
import com.tengju.support.domain.model.user.UserInfo;

import java.util.List;

public class MessageFactory {


    public static List<Message> create(MessageTask messageContent, BatchId batchId, List<UserInfo> receiveUser, SendStatus sendStatus) {

        List<Message> messageBatchRelationList = Lists.newArrayList();

        for (UserInfo userInfo : receiveUser) {

            MessageExtra extra =
                    new MessageExtra(userInfo.getAreaCode(), userInfo.getMobile());

            MessageType messageType = messageContent.getMessageType();
            MessageChannel messageChannel = MessageChannel.parseByMessageType(messageType);
            String title = "";
            String imgUrl = "";
            String content = "";
            String jumpUrl = "";
            if (messageChannel == MessageChannel.STATION_LETTER) {
                title = messageContent.getTitle();
                imgUrl = messageContent.getImgUrl();
                content = messageContent.getContent();
                jumpUrl = messageContent.getJumpUrl();
            }

            Message message = new Message(
                    messageContent.getTaskId(),
                    messageType,
                    batchId,
                    userInfo.getUserId(),
                    ReadStatus.UNREAD,
                    sendStatus,
                    messageContent.getSendTime(),
                    extra,
                    title,
                    imgUrl,
                    content,
                    jumpUrl
            );
            messageBatchRelationList.add(message);

        }

        return messageBatchRelationList;

    }


}
